package tools

import (
	"strconv"
)

//Uint64 get uint64 from map[string]string by key
func Uint64(m map[string]string, key string) (n uint64, ok bool) {
	s, ok := m[key]
	if !ok {
		return
	}
	n, e := strconv.ParseUint(s, 10, 64)
	if e != nil {
		ok = false
		return
	}
	return
}

//Uint32 get uint32 from map[string]string by key
func Uint32(m map[string]string, key string) (n uint32, ok bool) {
	s, ok := m[key]
	if !ok {
		return
	}
	t, e := strconv.ParseUint(s, 10, 32)
	if e != nil {
		ok = false
		return
	}
	n = uint32(t)
	return
}

//Int64 get int64 from map[string]string by key
func Int64(m map[string]string, key string) (n int64, ok bool) {
	s, ok := m[key]
	if !ok {
		return
	}
	n, e := strconv.ParseInt(s, 10, 64)
	if e != nil {
		ok = false
		return
	}
	return
}

//Int32 get int32 from map[string]string by key
func Int32(m map[string]string, key string) (n int32, ok bool) {
	s, ok := m[key]
	if !ok {
		return
	}
	t, e := strconv.ParseInt(s, 10, 32)
	if e != nil {
		ok = false
		return
	}
	n = int32(t)
	return
}
